//
//  WHEnterpriseCompanyModel.m
//  WHEasyBizLink
//
//  Created by shengmeng chen on 2024/11/29.
//

#import "WHEnterpriseCompanyModel.h"
#import "CommonTools.h"
#import "WHWproxyKitUtility.h"
#import "NSObject+MJKeyValue.h"

@implementation WHEnterpriseCompanyModel

/*查询单位信息
    入参描述：
    {
        "callMainTdsProc": "1",
        "callFromType": "0",
        "userid":"000000",
        "procId":"Pkg_Company.p_Company_List",
        "currPage": 1,
        "perPageCount": 26,
        "udid":"注册手机唯一标识",
        "conditions":"查询条件",
        "operuri" : "操作人标识",
        "operunm" : "操作人姓名"
    }
    conditions格式
    <cs>
      <c id="comid">单位标识</c>
      <c id="comname">单位名称</c>
      <c id="opertime1">起始时间<c>
      <c id="opertime2">终止时间<c>
    </cs>
  
    出参描述：
    {
      "dataListAllCount": 123,
      "dataList": [
        {
          "rn": "1",
          "comid": "单位标识",
          "comname": "单位名称",
          "comcode": "机构代码",
          "regtype": "开户方式",
          "comtype": "单位类型",
          "regionid": "所属区域",
          "regionnm": "所属区域名称",
          "banknm": "开户银行",
          "accountnm": "银行账户名称",
          "accountno": "银行账号",
          "linktel": "单位电话",
          "addr": "单位地址",
          "isctr": "是否物联管理单位 1-是 0-不是",
          "domainuri": "平台标识",
          "domainname": "平台名称",
          "netno": "网络号",
          "isself": "是否本机注册 1-是 0-不是",
          "sort": "排序号"
        }
      ],
      "code": "EC00",
      "msg": "处理成功"
    }
*/
//pragma mark 查询单位信息
+(void)qryListCompanyWithFromdata:(NSDictionary *)fromdata
               succesefulBlock:(void (^)(id responseObject))succese
               andFailureBlock:(void (^)(NSString *error))failure{
   
    //参数
    NSString *json = [NSString stringWithFormat:@"\"callMainTdsProc\":\"%@\"",@"1"];
    json = [json stringByAppendingFormat:@",\"callFromType\":\"0\""];
    json = [json stringByAppendingFormat:@",\"userid\":\"000000\""];
    json = [json stringByAppendingFormat:@",\"procId\":\"Pkg_Company.p_Company_List\""];
    json = [json stringByAppendingFormat:@",\"currPage\":\"%@\"",[CommonTools checkStringIsNull:fromdata[@"currPage"]]];
    json = [json stringByAppendingFormat:@",\"perPageCount\":\"%@\"",[CommonTools checkStringIsNull:fromdata[@"perPageCount"]]];
    json = [json stringByAppendingFormat:@",\"udid\":\"%@\"",[CommonTools checkStringIsNull:fromdata[@"udid"]]];
    json = [json stringByAppendingFormat:@",\"conditions\":\"<cs><c id=\\\"comid\\\"></c><c id=\\\"comname\\\">%@</c><c id=\\\"opertime1\\\"></c><c id=\\\"opertime2\\\"></c></cs>\"",[CommonTools checkStringIsNull:fromdata[@"conditions"]]];
    json = [json stringByAppendingFormat:@",\"operuri\":\"%@\"",kApp.userQcode];
    json = [json stringByAppendingFormat:@",\"operunm\":\"%@\"",kApp.userName];
    
    NSString *soapStr = [NSString stringWithFormat:@"{%@}",json];
    
    NSString * proxy  = [CommonTools checkStringIsNull:fromdata[@"proxy"]];
    NSString * target = [CommonTools checkStringIsNull:fromdata[@"target"]];
    
    WHWproxyKitUtility *whwProxyKit = [[WHWproxyKitUtility new] initWithProxyIP:proxy targetUri:target getParams:soapStr];
    whwProxyKit.mParamsHaveEncoded = YES;
    whwProxyKit.mUserType = @"0";
    [whwProxyKit getSyncActionWithprogress:^(NSString * _Nonnull result) {
    } success:^(NSString * _Nonnull result,NSString * _Nonnull xml, NSString * _Nonnull path){

        NSData *jsonData  = [xml dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
        NSString*code = dict[REQUEST_RESP_CODE];
        NSString*msg  = dict[REQUEST_RESP_MSG];

        if ([code isEqualToString:REQUEST_RESP_EC00]){
            NSArray *dataList  = dict[@"dataList"];
            succese([WHEnterpriseCompanyModel objectArrayWithKeyValuesArray:dataList]);
        }else{
            failure(msg);
        }
    } failure:^(NSString * _Nonnull result) {
        failure(result);
    }];
}



@end
